package com.xuecheng;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xuecheng.auth.confi.SendTenXunYunSmsUtil;
import com.xuecheng.auth.config.RedisUtils;
import com.xuecheng.ucenter.mapper.Iuser;
import com.xuecheng.ucenter.mapper.UserMapper;
import com.xuecheng.ucenter.model.po.User;
import com.xuecheng.ucenter.model.po.Users;
import com.xuecheng.ucenter.model.po.menu;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@SpringBootTest
public class test {
    @Autowired
    Iuser usera;
//查找全部
    @Test
    void test01() {
        List<User> users = usera.selectList(null);
        System.out.println(users);
    }
//查找id
    @Test
    public void testSelectById() {
        User use = usera.selectById(1);
        System.out.println(use);
    }

    //测试更新
    @Test
    public void testUpdate(){
        User user = new User();
        //可以通过条件自动拼接动态SQL
        user.setId(1);
        user.setName("续江");
        //updateById 参数是一个对象！
        int i = usera.updateById(user);
        System.out.println(i);
    }
    @Autowired
    RedisUtils utils;
    @Test
    void  test12(){
        utils.set("name","123");
        String name = utils.get("name").toString();
        System.out.println(name);
    }

    @Resource
    private SendTenXunYunSmsUtil sendTenXunSmsUtil;
    @Test
    void contextLoads() {
        sendTenXunSmsUtil.send("18735914857");
    }

    //批量查询
    @Test
    public void selectBatchIds(){
        List<User> users = usera.selectBatchIds(Arrays.asList(1, 2, 3));
        users.forEach(System.out::println);
    }
//查询
    @Test
    void WrapperTest(){
        //查询name、邮箱不为空且年龄大于等于20的用户
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone","18735914857");
        User user = usera.selectOne(wrapper);
        System.out.println(user);
//        wrapper.eq("name","续江");
//        User user = usera.selectOne(wrapper);
        System.out.println(user);
//        usera.selectList(wrapper).forEach(System.out::println);
    }

    @Test
    void WrapperTest4(){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper
                .notLike("name","a")    //查询姓名中不包含a的用户
                .likeRight("email","t");   //左和右是代表%的位置 两边都要匹配则为%e%，这里是email以t开头的 t%
        List<Map<String, Object>> maps = usera.selectMaps(wrapper);
        maps.forEach(System.out::println);
    }

    //联表查询
    @Test
    void WrapperTest5(){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.inSql("id","select id from user where id < 4");
        List<Object> objects = usera.selectObjs(wrapper);
        objects.forEach(System.out::println);
    }

    @Test
    void WrapperTest6() {
        //通过ID进行排序
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("id");   //通过id升序
        List<User> users = usera.selectList(wrapper);
        users.forEach(System.out::println);
    }
    @Autowired
    UserMapper mapper;
    @Test
    void tesl(){
        List<menu> menus = mapper.selectRolesByUserId(1);
        menus.forEach(System.out::println);
}

@Test
    public void aaa(){
    Users lijiazhu = mapper.selectUserById("lijiazhu");
    System.out.println(lijiazhu);

}

}
